import { createRouter, createWebHistory } from 'vue-router'

const routes = [
  {
    path: '/',
    redirect: '/dashboard'
  },
  {
    path: '/dashboard',
    name: 'Dashboard',
    component: () => import('../views/Dashboard.vue'),
    meta: { title: '控制台' }
  },
  {
    path: '/tasks',
    name: 'Tasks',
    component: () => import('../views/Tasks.vue'),
    meta: { title: '任务管理' }
  },
  {
    path: '/tasks/create',
    name: 'CreateTask',
    component: () => import('../views/TaskCreate.vue'),
    meta: { title: '创建任务' }
  },
  {
    path: '/tasks/:id/edit',
    name: 'EditTask',
    component: () => import('../views/TaskEdit.vue'),
    meta: { title: '编辑任务' }
  },
  {
    path: '/tasks/:id',
    name: 'TaskDetail',
    component: () => import('../views/TaskDetail.vue'),
    meta: { title: '任务详情' }
  },
  {
    path: '/repositories',
    name: 'Repositories',
    component: () => import('../views/Repositories.vue'),
    meta: { title: '代码库管理' }
  },
  {
    path: '/repositories/create',
    name: 'CreateRepository',
    component: () => import('../views/RepositoryCreate.vue'),
    meta: { title: '添加代码库' }
  },
  {
    path: '/executions',
    name: 'Executions',
    component: () => import('../views/Executions.vue'),
    meta: { title: '执行记录' }
  },
  {
    path: '/executions/:id',
    name: 'ExecutionDetail',
    component: () => import('../views/ExecutionDetail.vue'),
    meta: { title: '执行详情' }
  },
  {
    path: '/logs',
    name: 'Logs',
    component: () => import('../views/Logs.vue'),
    meta: { title: '日志管理' }
  },
  {
    path: '/files',
    name: 'Files',
    component: () => import('../views/Files.vue'),
    meta: { title: '文件管理' }
  },
  {
    path: '/settings',
    name: 'Settings',
    component: () => import('../views/Settings.vue'),
    meta: { title: '系统设置' }
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes
})

router.beforeEach((to, from, next) => {
  // 设置页面标题
  if (to.meta.title) {
    document.title = `${to.meta.title} - Tete1 Git同步系统`
  }
  next()
})

export default router